{% extends "base.html" %}
{% block title %}
    知了传课-首页
{% endblock %}
{% block head %}
    <script src="{{ url_for('static',filename="jquery/jquery.3.6.min.js") }}"></script>
    <script src="{{ url_for('static',filename="js/register.js") }}"></script>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/index.css') }}">
{% endblock %}
{% block body %}
    <div class="container">
        <div class="row" style="margin-top: 20px;">
            <div class="col"></div>
            <div class="col-10">
                <ul class="question-ul">
                    {% for quesion in pagination.items %}
                        <li>
                            <div class="side-question">
                                <img class="side-question-avatar"
                                     src={{quesion.author.photo}} alt="">
                            </div>
                            <div class="question-main">
                                <div class="question-title"><a
                                        href="/qa/detail/{{ quesion.id }}">{{ quesion.question }}</a></div>
                                <div class="question-content">{{ quesion.content }}</div>
                                <div class="question-detail">
                                    <span class="question-author">{{ quesion.author.username }}</span>
                                    <span class="question-time">{{ quesion.join_time|my_format }}</span>
                                </div>
                            </div>
                        </li>
                    {% endfor %}
                </ul>
            </div>
            <div class="col"></div>
        </div>
    </div>

    {# 搜索分页 #}
    <p align="center">共{{ pagination.total }}条数据</p>
    {% if search_btn==1 %}
        <nav aria-label="Page navigation example" class="col-md-4 offset-md-4">

        <ul class="pagination">
            <li {% if pagination.has_prev %}
                class="page-item"
            {% else %} class="page-item disabled"
            {% endif %} >
                <a class="page-link" href="{{ url_for('qa.question_search', page=pagination.page - 1,keywords=mykeywords) }}" aria-label="Previous">
                    <span aria-hidden="true">&laquo;</span>
                </a>
            </li>
            {% if pagination.pages>6 %}
                {% if pagination.pages - pagination.page<7 %}
                    {% for i in range(pagination.pages - 6, pagination.pages + 1) %}
                        <li
                                {% if i == pagination.page %}
                                    class="active page-item"
                                {% else %} class="page-item"
                                {% endif %} ><a class="page-link" href="{{ url_for('qa.question_search', page=i,keywords=mykeywords) }}">{{ i }}</a>
                        </li>
                    {% endfor %}
                {% else %}
                    {% for i in range(pagination.page, pagination.page + 3) %}
                        <li
                                {% if i == pagination.page %}
                                    class="active page-item"
                                {% else %} class="page-item"
                                {% endif %} ><a class="page-link" href="{{ url_for('qa.question_search', page=i,keywords=mykeywords) }}">{{ i }}</a>
                        </li>
                    {% endfor %}

                    <li class="page-item"><a class="page-link" href="#">...</a></li>
                    {% for i in range(pagination.pages - 2, pagination.pages + 1) %}
                        <li
                                {% if i == pagination.page %}
                                    class="active page-item"
                                {% else %} class="page-item"
                                {% endif %} ><a class="page-link" href="{{ url_for('qa.question_search', page=i,keywords=mykeywords) }}">{{ i }}</a>
                        </li>
                    {% endfor %}

                {% endif %}

            {% else %}
                {% for i in range(1, pagination.pages + 1) %}
                    <li
                            {% if i == pagination.page %}
                                class="active page-item"
                            {% else %} class="page-item"
                            {% endif %} ><a class="page-link" href="{{ url_for('qa.question_search', page=i,keywords=mykeywords) }}">{{ i }}</a></li>
                {% endfor %}
            {% endif %}


            <li {% if pagination.has_next %}{#  #}
                class="page-item"
            {% else %} class="page-item disabled"
            {% endif %} >
                <a class="page-link" href="{{ url_for("qa.question_search", page=pagination.page + 1,keywords=mykeywords) }}" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                </a>
            </li>

        </ul>

    </nav>
    {% else %}
        <nav aria-label="Page navigation example" class="col-md-4 offset-md-4">

        <ul class="pagination">
            <li {% if pagination.has_prev %}
                class="page-item"
            {% else %} class="page-item disabled"
            {% endif %} >
                <a class="page-link" href="{{ url_for('qa.index', page=pagination.page - 1) }}" aria-label="Previous">
                    <span aria-hidden="true">&laquo;</span>
                </a>
            </li>
            {% if pagination.pages>6 %}
                {% if pagination.pages - pagination.page<7 %}
                    {% for i in range(pagination.pages - 6, pagination.pages + 1) %}
                        <li
                                {% if i == pagination.page %}
                                    class="active page-item"
                                {% else %} class="page-item"
                                {% endif %} ><a class="page-link" href="{{ url_for('qa.index', page=i) }}">{{ i }}</a>
                        </li>
                    {% endfor %}
                {% else %}
                    {% for i in range(pagination.page, pagination.page + 3) %}
                        <li
                                {% if i == pagination.page %}
                                    class="active page-item"
                                {% else %} class="page-item"
                                {% endif %} ><a class="page-link" href="{{ url_for('qa.index', page=i) }}">{{ i }}</a>
                        </li>
                    {% endfor %}

                    <li class="page-item"><a class="page-link" href="#">...</a></li>
                    {% for i in range(pagination.pages - 2, pagination.pages + 1) %}
                        <li
                                {% if i == pagination.page %}
                                    class="active page-item"
                                {% else %} class="page-item"
                                {% endif %} ><a class="page-link" href="{{ url_for('qa.index', page=i) }}">{{ i }}</a>
                        </li>
                    {% endfor %}

                {% endif %}

            {% else %}
                {% for i in range(1, pagination.pages + 1) %}
                    <li
                            {% if i == pagination.page %}
                                class="active page-item"
                            {% else %} class="page-item"
                            {% endif %} ><a class="page-link" href="{{ url_for('qa.index', page=i) }}">{{ i }}</a></li>
                {% endfor %}
            {% endif %}


            <li {% if pagination.has_next %}{#  #}
                class="page-item"
            {% else %} class="page-item disabled"
            {% endif %} >
                <a class="page-link" href="{{ url_for("qa.index", page=pagination.page + 1) }}" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                </a>
            </li>

        </ul>

    </nav>
    {% endif %}


{% endblock %}
